Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use modelName instead of typeKey when available, but preserve existing ID generation behavior #64

Merged
merged 3 commits into from
Jun 9, 2015

Conversation

rsutphin
Copy link
Collaborator

@rsutphin rsutphin commented Jun 8, 2015

This is my suggestion for #62, based on my desire to prevent all existing ember-pouch users from having to do a data migration as discussed in #63.

It also includes a set of very basic integration tests. If this feature doesn't get integrated, they should still be usable on their own. (I wrote them to verify that this change did preserve the prior behavior.)

@rsutphin
Copy link
Collaborator Author

rsutphin commented Jun 8, 2015

The integration tests work with PhantomJS 2.0 only, not 1.9. I thought from reading the .travis.yml that PhantomJS 2.0 was available on travis, but it appears not yet (travis-ci/travis-ci#3225).

So, the CI build is going to fail. I'll look into getting PhantomJS 2.0 available for the build.

@broerse
Copy link
Collaborator

broerse commented Jun 8, 2015

👍

@OleRoel
Copy link
Contributor

OleRoel commented Jun 8, 2015

👍 Looks good to me

@broerse
Copy link
Collaborator

broerse commented Jun 8, 2015

Tested on https://github.com/broerse/ember-cli-blog and it works fine!

@fsmanuel
Copy link
Collaborator

fsmanuel commented Jun 8, 2015

@rsutphin looks good but can we use the new terminology and do
recordModelName = this.getRecordModelName(type);

@rsutphin
Copy link
Collaborator Author

rsutphin commented Jun 8, 2015

@fsmanuel, I deliberately used a different term from either modelName or typeKey in order to prevent the sort of conceptual confusion @OleRoel and I discussed on #63:

I would not call it getModelName in order to prevent the sort of conceptual mismatch with ED that you're talking about. I'd call it something like getRecordTypeName or getTypeNameForDocumentId to indicate its purpose.

Do you think not calling it something that includes modelName is more confusing?

rsutphin added 2 commits June 8, 2015 08:41
Happy path only. Verifies only that records in PouchDB can be read into /
written from ember-data models.

Includes manually downloading PhantomJS 2.0 for Travis — the integration tests
don't work with PhantomJS 1.9.
This removes scads of deprecation warnings with ember-data 1.0-beta18
and later while preserving access to data created with current versions
of ember-pouch.

See pouchdb-community#63 for a discussion.
@rsutphin rsutphin force-pushed the record_type_name branch from 5e79a11 to 8aa35df Compare June 8, 2015 13:42
@rsutphin
Copy link
Collaborator Author

rsutphin commented Jun 8, 2015

Squashed the various CI-fixing commits.

@@ -131,7 +133,8 @@ export default DS.RESTAdapter.extend({

_recordToData: function (store, type, record) {
var data = {};
var serializer = store.serializerFor(type.typeKey);
var recordTypeName = this.getRecordTypeName(type);
var serializer = store.serializerFor(recordTypeName);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we get a problem here when ED transitions to dasherized types.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point. I initially used type.modelName || type.typeKey instead of getRecordTypeName in this method for that reason. But the serialized data comes back with a camelized key (see line 155 below), and I figured it wouldn't hurt to use the camelized version in both places.

ED has supported either dasherized or camelized names for lookups (modelFor, serializerFor, etc) for a while — have you seen something that indicates that it is going to stop supporting camelized ones at some point?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this some more — these uses are conceptually different from recordTypeName, so it's probably best not to use it here. E.g., if you override getRecordTypeName to provide your own scheme, the serializer is still going to return the data with a camelized key. And if the serializer changes in the future, it shouldn't affect the type name used in the record IDs. So I'll change this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 4b33181.

@fsmanuel
Copy link
Collaborator

fsmanuel commented Jun 8, 2015

@rsutphin i see your point. What do you think about two functions:

modelNameFromType(type) {
  if (type.modelName) {
    return type.modelName;
  } else {
    // This branch can be removed when the library drops support for
    // ember-data 1.0-beta17 and earlier.
    return type.typeKey;
  }
}
recordTypeName(type) {
  if (this.get('useLegacyTypes')) {
    return camelize(this.modelNameFromType(type));
  }

  return this.modelNameFromType(type);
}

If we call it a breaking change new users can use the dasherized types and old users should set useLegacyTypes. That way we can differentiate between ED and pouch internals (see my comment on store.serializerFor above).

@rsutphin
Copy link
Collaborator Author

rsutphin commented Jun 8, 2015

@fsmanuel, we could do that, but it seems unnecessary. Can you help me understand why you think this complexity (including a new option to document and support, communicating the breaking change to all existing users, etc.) is worth it just to use dasherized names in document IDs instead of camelized ones? The specific details of the document IDs aren't exposed to regular users of the adapter, so the risk of confusion with what ember-data does is very low.

I agree that the interaction with the serializer needs to be addressed; I'll push something up shortly to handle that.

@fsmanuel
Copy link
Collaborator

fsmanuel commented Jun 8, 2015

@rsutphin 👍

@nolanlawson
Copy link
Member

Nice work! Love the cross-version solution and the new tests. And nice hack to get PhantomJS 2.0 working; I didn't realize it was possible to run it in Travis. :)

Thanks for all the input, everyone! I'll publish a patch version today.

@nolanlawson
Copy link
Member

2.0.1 published and changelog in the README updated. Thanks again everyone!

@rsutphin rsutphin deleted the record_type_name branch June 9, 2015 15:45
rsutphin added a commit to rsutphin/ember-pouch that referenced this pull request Jun 11, 2015
N.b., the new test does not pass on ember-data 1.0-beta19 or 19.1.
The problem appears to be that the relationship returned by
eachRelationship has the name of the associated type instead of the
DS.Model object. It works fine on older versions (tested beta17 and 18).
Have not tried in a real app yet to see if this is a test artifact or
an ember-data bug.
rsutphin added a commit to rsutphin/ember-pouch that referenced this pull request Jun 11, 2015
N.b., the new test does not pass on ember-data 1.0-beta19 or 19.1.
The problem appears to be that the relationship returned by
eachRelationship has the name of the associated type instead of the
DS.Model object. It works fine on older versions (tested beta17 and 18).
Have not tried in a real app yet to see if this is a test artifact or
an ember-data bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants